# tag::COORDINATE[]
import typing

class Coordinate(typing.NamedTuple):
    lat: float
    lon: float

    def __str__(self):
        ns = 'N' if self.lat >= 0 else 'S'
        we = 'E' if self.lon >= 0 else 'W'
        return f'{abs(self.lat):.1f}°{ns}, {abs(self.lon):.1f}°{we}'
# end::COORDINATE[]


c1 = Coordinate(1.1, 2.2)
# c2 = Coordinate("1", "2")
print(c1)
# Although NamedTuple appears in the class statement as a super‐
# class, it’s actually not. typing.NamedTuple uses the advanced func‐
# tionality of a metaclass2 to customize the creation of the user’s
# class. Check this out:
# print(issubclass(Coordinate1, typing.NamedTuple))  报错：NamedTuple不是类！
print(issubclass(Coordinate, typing.NamedTupleMeta))  # False，是类但也不是其基类
print(issubclass(Coordinate, tuple))